home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1995…tember: Reference Library / Dev.CD Sep 95 RL / Dev.CD Sep 95 RL.toast / mac / Technical Documentation / develop / develop Issue 19 code / GX Bitmaps / AliasBM.c next >
Encoding:
C/C++ Source or Header  |  1994-07-21  |  2.6 KB  |  116 lines  |  [TEXT/KAHL]

  1. /*
  2. ••••••••••••••••••••
  3.     AliasBM.c
  4.     David Surovell
  5.  
  6.     this file contains 2 routines to assist in the creation of
  7.     gxBitmap shapes whose image data resides in an accessible
  8.     file. The file should contain valid image data, and should be large
  9.     enough to hold the enitre image as specified by the gxBitmap argument
  10. ••••••••••••••••••••
  11. */
  12.  
  13. #include <Types.h>
  14. #include <Errors.h>
  15. #include <Memory.h>
  16. #include <Resources.h>
  17. #include <Files.h>
  18. #include <Aliases.h>
  19.  
  20. #include "graphics types.h"
  21. #include "graphics errors.h"
  22. #include "graphics routines.h"
  23.  
  24.  
  25. gxShape CreateDiskBitmap(
  26.     FSSpec        *fsData,
  27.     gxBitmap        *targetBM );
  28. gxTag CreateBitmapAliasTag(
  29.     FSSpec        *bitmapFS,
  30.     unsigned long    fileOffset );
  31.  
  32.  
  33.  
  34. gxShape CreateDiskBitmap(
  35.     FSSpec        *fsData,
  36.     gxBitmap        *targetBM )
  37. {
  38. gxBitmap        localBM;
  39. gxShape        targetShape;
  40. gxTag        targetTag;
  41.  
  42.     if ((fsData == nil) || (targetBM == nil))
  43.         return nil;
  44.  
  45.     targetShape = nil;
  46.  
  47.     targetTag = CreateBitmapAliasTag( fsData, 0L );
  48.     if (targetTag != nil)
  49.     {
  50.         localBM = *targetBM;
  51.         localBM.image = (Ptr)gxBitmapFileAliasImageValue;
  52.         targetShape = GXNewBitmap( &localBM, nil );
  53.  
  54.         if (targetShape != nil)
  55.             GXSetShapeTags( targetShape, gxBitmapFileAliasTagType, 1L, -1L, 1L, &targetTag );
  56.         GXDisposeTag( targetTag );
  57.     }
  58.  
  59.     return targetShape;
  60. }
  61.  
  62.  
  63. gxTag CreateBitmapAliasTag(
  64.     FSSpec        *bitmapFS,
  65.     unsigned long    fileOffset )
  66. {
  67. struct gxBitmapDataSourceAlias    *aliasRecordPtr;
  68. gxTag                        targetTag;
  69. FSSpec                        targetFS;
  70. AliasHandle                    aliasHdl;
  71. OSErr                        iErr;
  72. long                            aliasSize, aliasRecordSize;
  73. Boolean                        wasChanged;
  74.  
  75.     targetTag = nil;
  76.     aliasHdl = nil;
  77.     aliasRecordPtr = nil;
  78.  
  79.     // create an alias and resolve it
  80.     iErr = NewAlias( nil, bitmapFS, &aliasHdl );
  81.     if (iErr == noErr)
  82.         iErr = ResolveAlias( nil, aliasHdl, &targetFS, &wasChanged );
  83.  
  84.     // build up a compact representation for inclusion into a gxTag */
  85.     if (iErr == noErr)
  86.     {
  87.         aliasSize = GetHandleSize( (Handle)aliasHdl );
  88.         aliasRecordSize = aliasSize + 2 * sizeof( long );
  89.         aliasRecordPtr = (struct  gxBitmapDataSourceAlias*)NewPtr( aliasRecordSize );
  90.         iErr = MemError();
  91.     }
  92.  
  93.     // create the gxTag
  94.     if (iErr == noErr)
  95.     {
  96.         // create gxBitmapDataSourceAlias with specified fileOffset
  97.         // and appropriate aliasRecordSize and aliasRecord
  98.         aliasRecordPtr->fileOffset = fileOffset;
  99.         aliasRecordPtr->aliasRecordSize = aliasSize;
  100.         BlockMove( *aliasHdl, &aliasRecordPtr->aliasRecord[0], aliasSize );
  101.  
  102.         targetTag = GXNewTag( gxBitmapFileAliasTagType, aliasRecordSize, aliasRecordPtr );
  103.     }
  104.  
  105.     // clean up
  106.     if (aliasHdl != nil)
  107.         DisposeHandle( (Handle)aliasHdl );
  108.     if (aliasRecordPtr != nil)
  109.         DisposePtr( (Ptr)aliasRecordPtr );
  110.  
  111.     return targetTag;
  112. }
  113.  
  114.  
  115.  
  116.